package svc

import (
	"github.com/zeromicro/go-zero/core/stores/sqlx"
	"go-admin/base/dao"
	"go-admin/base/internal/config"
	model "go-admin/base/mongo"
)

type ServiceContext struct {
	Config              config.Config
	UserModel           dao.UserModel
	RoleModel           dao.RoleModel
	PermissionModel     dao.PermissionModel
	UserRoleModel       dao.UserRoleModel
	RolePermissionModel dao.RolePermissionModel
	GroupModel          dao.GroupModel
	UserGroupModel      dao.UserGroupModel
	Conn                sqlx.SqlConn
	MessageModel        model.MessageModel
}

func NewServiceContext(c config.Config) *ServiceContext {
	conn := sqlx.NewMysql(c.MySQL.DataSource)
	return &ServiceContext{
		Config:              c,
		UserModel:           dao.NewUserModel(conn),
		RoleModel:           dao.NewRoleModel(conn),
		PermissionModel:     dao.NewPermissionModel(conn),
		UserRoleModel:       dao.NewUserRoleModel(conn),
		RolePermissionModel: dao.NewRolePermissionModel(conn),
		GroupModel:          dao.NewGroupModel(conn),
		UserGroupModel:      dao.NewUserGroupModel(conn),
		Conn:                conn,
		MessageModel:        model.NewMessageModel(c.Mongo.Uri, c.Mongo.Db, c.Mongo.Collection),
	}
}
